package com.sdry.web.controller.jyy;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.PushPayload;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.jyy.Shedu;
import com.sdry.model.jyy.SheduExample;
import com.sdry.model.jyy.Shedudetail;
import com.sdry.model.jyy.ShedudetailExample;
import com.sdry.model.jyy.ShedudetailExample.Criteria;
import com.sdry.model.llm.Role;
import com.sdry.model.llm.User;
import com.sdry.service.jyy.SheduServise;
import com.sdry.service.jyy.ShedudetailServise;
import com.sdry.utils.DateUtil;
import com.sdry.utils.ExcelUtils;
import com.sdry.utils.PushExample;
import com.sdry.utils.PushUtils;
import com.sdry.utils.ResponseUtil;

/**
 * @ClassName:    [sheduController]   
 * @Description:  [一句话描述该类的功能]   
 * @Author:       [jyy]   
 * @CreateDate:   [2018年11月9日 下午5:02:39]    
 * @Version:      [v1.0]
 */
@Controller
@RequestMapping("/shedu")
public class SheduController {
	
	@Resource
	private SheduServise sheduServise;
	
	@Resource
	private ShedudetailServise shedudetailServise;

	@RequestMapping("/shedu")
	public String toShedu() {
		return "/jyy/monthshedu4";
	}
	
	/**删除排产单
	 * @throws Exception */
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response) throws Exception {
		
		int affact = 0;
		String[] split = ids.split(",");
		for (String s : split) {
			Long id = Long.valueOf(s);
			ShedudetailExample example = new ShedudetailExample();
			Criteria createCriteria = example.createCriteria();
			createCriteria.andRemark2EqualTo(s);
			affact = shedudetailServise.deleteByExample(example);
			affact = sheduServise.deleteById(id);
		}
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 根据 产品 和 工位 查询排产单
	 * @param product 产品
	 * @param position 工位
	 * @param response 响应
	 * @throws Exception  异常
	 */
	@RequestMapping("/selectByDate")
	public void selectByDate(String format,String product,String position,HttpServletResponse response) throws Exception {
		
		String num = "";
		int num2= 0;
		ShedudetailExample example = new ShedudetailExample();
		Criteria createCriteria = example.createCriteria();
		
		createCriteria.andRemark1EqualTo(format);
		//根据时间查询排产单
		List<Shedudetail> list = shedudetailServise.selectByExample(example );
		
		if(list.size() >0) {
			/*if("膜丝".equals(position)) {
				if("PSH2-0960-T-01".equals(product)) {
					//b1
					num = list.get(0).getB1();
				}else if("PSH2-0980-T-02".equals(product)) {
					//c1
					num = list.get(0).getC1();
				}else if("PSH1-1080-C-04".equals(product)) {
					//d1
					num = list.get(0).getD1();
				}else if("PSH1-1060-B-03".equals(product)) {
					//e1
					num = list.get(0).getE1();
				}
				
			}else */if("组装".equals(position)) {
				if("PSH2-0960-T-01".equals(product)) {
					//b4
					num = list.get(0).getB4();
				}else if("PSH2-0980-T-02".equals(product)) {
					//c4
					num = list.get(0).getC4();
				}else if("PSH1-1080-C-04".equals(product)) {
					//d4
					num = list.get(0).getD4();
				}else if("PSH1-1060-B-03".equals(product)) {
					//e4
					num = list.get(0).getE4();
				}
			}else if("离心".equals(position)) {
				if("PSH2-0960-T-01".equals(product)) {
					//b7
					num = list.get(0).getB7();
				}else if("PSH2-0980-T-02".equals(product)) {
					//c7
					num = list.get(0).getC7();
				}else if("PSH1-1080-C-04".equals(product)) {
					//d7
					num = list.get(0).getD7();
				}else if("PSH1-1060-B-03".equals(product)) {
					//e7
					num = list.get(0).getE7();
				}
			}else if("固化".equals(position)) {
				if("PSH2-0960-T-01".equals(product)) {
					//b9
					num = list.get(0).getB9();
				}else if("PSH2-0980-T-02".equals(product)) {
					//c9
					num = list.get(0).getC9();
				}else if("PSH1-1080-C-04".equals(product)) {
					//d9
					num = list.get(0).getD9();
				}else if("PSH1-1060-B-03".equals(product)) {
					//e9
					num = list.get(0).getE9();
				}
			}else if("切割".endsWith(position)) {
				if("PSH2-0960-T-01".equals(product)) {
					//b10
					num = list.get(0).getB10();
				}else if("PSH2-0980-T-02".equals(product)) {
					//c10
					num = list.get(0).getC10();
				}else if("PSH1-1080-C-04".equals(product)) {
					//d10
					num = list.get(0).getD10();
				}else if("PSH1-1060-B-03".equals(product)) {
					//e10
					num = list.get(0).getE10();
				}
			}
			
			if(num.equals(null) || "".equals(num)) {
				ResponseUtil.write(response, num2);
			}else {
				ResponseUtil.write(response, num);
			}
		}else {
			ResponseUtil.write(response, num2);
		}
	}
	
	@RequestMapping("/selectByDate2")
	public void selectByDate2(String format,String product,String chanxian,HttpServletResponse response) throws Exception {
		String num = "";
		int num2= 0;
		ShedudetailExample example = new ShedudetailExample();
		Criteria createCriteria = example.createCriteria();
		
		createCriteria.andRemark1EqualTo(format);
		//根据时间查询排产单
		List<Shedudetail> list = shedudetailServise.selectByExample(example );
		
		if(list.size() >0) {
			if(chanxian != null && chanxian != "") {
				
				if(chanxian.contains("热法")) {
					if(chanxian.contains("1")) {
						if("PSH2-0960-T-01".equals(product)) {
							num = list.get(0).getC09601();
						}else if("PSH2-0980-T-02".equals(product)) {
							num = list.get(0).getC09801();
						}
				    }else if(chanxian.contains("2")) {
						if("PSH2-0960-T-01".equals(product)) {
							num = list.get(0).getC09602();
						}else if("PSH2-0980-T-02".equals(product)) {
							num = list.get(0).getC09802();
						}
				    }else if(chanxian.contains("3")) {
						if("PSH2-0960-T-01".equals(product)) {
							num = list.get(0).getC09603();
						}else if("PSH2-0980-T-02".equals(product)) {
							num = list.get(0).getC09803();
						}
				    }else if(chanxian.contains("4")) {
						if("PSH2-0960-T-01".equals(product)) {
							num = list.get(0).getC09604();
						}else if("PSH2-0980-T-02".equals(product)) {
							num = list.get(0).getC09804();
						}
				    }
				}else if(chanxian.contains("湿法")) {
					if(chanxian.contains("1")) {
						if("PSH1-1060-B-03".equals(product)) {
							num = list.get(0).getC10601();
						}else if("PSH1-1080-C-04".equals(product)) {
							num = list.get(0).getC10801();
						}
				    }else if(chanxian.contains("2")) {
						if("PSH1-1060-B-03".equals(product)) {
							num = list.get(0).getC10602();
						}else if("PSH1-1080-C-04".equals(product)) {
							num = list.get(0).getC10802();
						}
				    }
				}
			}
			
			if(num != null && num != ""){
				ResponseUtil.write(response, num);
			}else {
				ResponseUtil.write(response, num2);
			}
		}else {
			ResponseUtil.write(response, num2);
		}
	}
	
	/**
	 * 根据登录人查询权限
	 * @param response
	 * @param request
	 * @throws Exception
	 */
	@RequestMapping("/selectAuthority")
	public void selectAuthority( HttpServletResponse response,HttpServletRequest request) throws Exception {
		int affact = 0;
		int count = 0;
		//获取session中的人名
		User people = (User) request.getSession().getAttribute("currentUser");
		
		//根据人员id查询当前登录人的权限
		List<Role>  list = sheduServise.selectAuthority(people.getUid());
		
		if( list.size() >0) {
			for (Role role : list) {
				if(role.getName() != null && role.getName() != "") {
					if("SHE主管".equals(role.getName())) {
						count = count+1;
					}else {
						//当前登录人不是生产主管，不能审批
						affact = -1;
					}
				}else {
					//当前登录人没有角色名称
					affact = -2;
				}
			}
		}else {
			//当前登录人没有角色
			affact = -3;
		}
		
		if(count >0) {
			affact = 1;
		}
		
		ResponseUtil.write(response, affact);
	}
	
	
	/**
	 * 根据排产单id修改（审批后修改审批相关字段）
	 * @param shedu 排产单实体
	 * @param response 响应
	 * @throws Exception 异常
	 */
	@RequestMapping("/edit")
	public void edit(Shedu shedu, HttpServletResponse response,HttpServletRequest request) throws Exception {
		int affact = 0;
		String format2 = DateUtil.dateFormat1();
		
		//获取session中的人名
		User people = (User) request.getSession().getAttribute("currentUser");
		
		//审批人
		shedu.setRemark(people.getUserName());
		//审批时间
		shedu.setRemark2(format2);
		affact = sheduServise.updateByPrimaryKeySelective(shedu);
		
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 查询排产单列表
	 * @param shedu 排产单实体
	 * @param response 响应参数
	 * @param limit 每页记录数
	 * @param page 页码
	 * @throws Exception 异常
	 */
	@RequestMapping("/selectList")
	public void selectList(Shedu shedu, HttpServletResponse response, 
			@RequestParam(value = "limit",required = false)int limit,
            @RequestParam(value = "page",required = false)int page) throws Exception {
		
		PageHelper.startPage(page, limit);
		
		SheduExample example = new SheduExample();
		List<Shedu> list = sheduServise.selectByExample(example );
		
		PageInfo<Shedu> info = new PageInfo<Shedu>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 查询排产单明细
	 * @param shedudetail  明细实体
	 * @param response 响应
	 * @param limit 每页显示记录数
	 * @param page 页码
	 * @throws Exception  异常
	 */
	@RequestMapping("/selecDetailtList")
	public void selecDetailtList(Shedudetail shedudetail, HttpServletResponse response, 
			@RequestParam(value = "limit",required = false)int limit,
            @RequestParam(value = "page",required = false)int page) throws Exception {
		
		PageHelper.startPage(page, limit);
		
		ShedudetailExample example = new ShedudetailExample();
		Criteria createCriteria = example.createCriteria();
		if(shedudetail.getRemark1() != null && shedudetail.getRemark1() != "") {
			createCriteria.andRemark1EqualTo(shedudetail.getRemark1());
		}
		if(shedudetail.getRemark2() != null && shedudetail.getRemark2() != "") {
			createCriteria.andRemark2EqualTo(shedudetail.getRemark2());
		}
		
		List<Shedudetail> list = shedudetailServise.selectByExample(example);
		
		PageInfo<Shedudetail> info = new PageInfo<Shedudetail>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 导入模板的表头
	 * @return
	 */
	public List<String> names(){
		List<String> list = new ArrayList<>();
		list.add("时间");
		
		list.add("膜丝烘干a");
		list.add("膜丝缓存a");
		list.add("膜芯制作a");
		list.add("组件组装a");
		list.add("膜丝切割a");
		list.add("浇铸端盖安装a");
		list.add("组件吊装离心a");
		list.add("浇铸端盖拆卸a");
		list.add("组件预固化缓存a");
		list.add("组件切割a");
		
		list.add("膜丝烘干b");
		list.add("膜丝缓存b");
		list.add("膜芯制作b");
		list.add("组件组装b");
		list.add("膜丝切割b");
		list.add("浇铸端盖安装b");
		list.add("组件吊装离心b");
		list.add("浇铸端盖拆卸b");
		list.add("组件预固化缓存b");
		list.add("组件切割b");
		
		list.add("膜丝烘干c");
		list.add("膜丝缓存c");
		list.add("膜芯制作c");
		list.add("组件组装c");
		list.add("膜丝切割c");
		list.add("浇铸端盖安装c");
		list.add("组件吊装离心c");
		list.add("浇铸端盖拆卸c");
		list.add("组件预固化缓存c");
		list.add("组件切割c");
		
		list.add("膜丝烘干d");
		list.add("膜丝缓存d");
		list.add("膜芯制作d");
		list.add("组件组装d");
		list.add("膜丝切割d");
		list.add("浇铸端盖安装d");
		list.add("组件吊装离心d");
		list.add("浇铸端盖拆卸d");
		list.add("组件预固化缓存d");
		list.add("组件切割d");
		
		list.add("膜丝烘干e");
		list.add("膜丝缓存e");
		list.add("膜芯制作e");
		list.add("组件组装e");
		list.add("膜丝切割e");
		list.add("浇铸端盖安装e");
		list.add("组件吊装离心e");
		list.add("浇铸端盖拆卸e");
		list.add("组件预固化缓存e");
		list.add("组件切割e");
		
		list.add("09601");
		list.add("09801");
		list.add("09602");
		list.add("09802");
		list.add("09603");
		list.add("09803");
		list.add("09604");
		list.add("09804");
		list.add("10601");
		list.add("10801");
		list.add("10602");
		list.add("10802");
		
		return list;
	}
	
	/**
	 * 导入生产计划
	 * @param filename
	 * @param response
	 * @throws IOException 
	 * @throws IllegalStateException 
	 */
	@RequestMapping(value = "/uploadPlan", method = RequestMethod.POST)
	@ResponseBody
	public void uploadPlan(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
		 String savePath = request.getSession().getServletContext().getRealPath("/WEB-INF/"+file.getOriginalFilename());
		 File newFile=new File(savePath);
		 
		   //通过CommonsMultipartFile的方法直接写文件（注意这个时候）
	       file.transferTo(newFile);
	       
	       //取文件后缀
	       String subfix = savePath.lastIndexOf(".")==-1? "" : savePath.substring(savePath.lastIndexOf(".")+1);
	       //System.out.println(subfix);
	       List<List<String>> lists = new ArrayList<>();
	      
	       //获取导入行数
	       List<String> names = names();
	       int num = names.size();
	       if(subfix.equals("xls")){
	    	   lists = ExcelUtils.readXls(savePath, request,num);
	 	   }else if(subfix.equals("xlsx")){
	 		   lists = ExcelUtils.readXlsx(savePath, request,num);
	 	   }else{
	 	   		response.getWriter().print("0");
	 	   }
	       
	      int flag = 1; 
	      Long id = null;
	      Shedu shedu = new Shedu();
	      int affact = 0;
	       for (int i = 1; i < lists.size(); i++) {
	    	   List<String> list = new ArrayList<>();
	    	   list= lists.get(i);
	    
	    	   //获取第一行要导入的数据，第一列为“已有时间”
	    	   if(i == 1) {
	    		   shedu.setHavetime(list.get(0));
	    		   //保存排产单
	    		   shedu.setRemark3("未提交");
	    		   affact = sheduServise.insert(shedu);
	    		   if(affact > 0) {
	    			   //获取返回排产单id
	    			   id = shedu.getId();
	    		   }
	    	   }
	    	   //第二行第一列为“开始时间”
	    	   if(i == 2) {
	    		   shedu.setId(id);
	    		   shedu.setStarttime(list.get(0));
	    		   //根据id动态修改排产单
	    		   sheduServise.updateByPrimaryKeySelective(shedu);
	    	   }
	    	   //最后一行第一列为“结束时间”
	    	   if(i == lists.size() - 1) {
	    		   shedu.setId(Long.valueOf(id));
	    		   shedu.setEndtime(list.get(0));
	    		   sheduServise.updateByPrimaryKeySelective(shedu);
	    	   }
	    	   
	    	   
	    	   Shedudetail shedudetail = new Shedudetail();
	    	   
	    	   //如果，排产单id存在，将详情与排产单关联
	    	   if(id > 0) {
	    		   shedudetail.setRemark2(id+"");
	    	   }
	    	   
	    	   shedudetail.setRemark1(list.get(0));
	    	   shedudetail.setA1(list.get(1));
	    	   shedudetail.setA2(list.get(2));
	    	   shedudetail.setA3(list.get(3));
	    	   shedudetail.setA4(list.get(4));
	    	   shedudetail.setA5(list.get(5));
	    	   shedudetail.setA6(list.get(6));
	    	   shedudetail.setA7(list.get(7));
	    	   shedudetail.setA8(list.get(8));
	    	   shedudetail.setA9(list.get(9));
	    	   shedudetail.setA10(list.get(10));
	    	   
	    	   shedudetail.setB1(list.get(11));
	    	   shedudetail.setB2(list.get(12));
	    	   shedudetail.setB3(list.get(13));
	    	   shedudetail.setB4(list.get(14));
	    	   shedudetail.setB5(list.get(15));
	    	   shedudetail.setB6(list.get(16));
	    	   shedudetail.setB7(list.get(17));
	    	   shedudetail.setB8(list.get(18));
	    	   shedudetail.setB9(list.get(19));
	    	   shedudetail.setB10(list.get(20));
	    	   
	    	   shedudetail.setC1(list.get(21));
	    	   shedudetail.setC2(list.get(22));
	    	   shedudetail.setC3(list.get(23));
	    	   shedudetail.setC4(list.get(24));
	    	   shedudetail.setC5(list.get(25));
	    	   shedudetail.setC6(list.get(26));
	    	   shedudetail.setC7(list.get(27));
	    	   shedudetail.setC8(list.get(28));
	    	   shedudetail.setC9(list.get(29));
	    	   shedudetail.setC10(list.get(30));
	    	   
	    	   shedudetail.setD1(list.get(31));
	    	   shedudetail.setD2(list.get(32));
	    	   shedudetail.setD3(list.get(33));
	    	   shedudetail.setD4(list.get(34));
	    	   shedudetail.setD5(list.get(35));
	    	   shedudetail.setD6(list.get(36));
	    	   shedudetail.setD7(list.get(37));
	    	   shedudetail.setD8(list.get(38));
	    	   shedudetail.setD9(list.get(39));
	    	   shedudetail.setD10(list.get(40));
	    	   
	    	   shedudetail.setE1(list.get(41));
	    	   shedudetail.setE2(list.get(42));
	    	   shedudetail.setE3(list.get(43));
	    	   shedudetail.setE4(list.get(44));
	    	   shedudetail.setE5(list.get(45));
	    	   shedudetail.setE6(list.get(46));
	    	   shedudetail.setE7(list.get(47));
	    	   shedudetail.setE8(list.get(48));
	    	   shedudetail.setE9(list.get(49));
	    	   shedudetail.setE10(list.get(50));
	    	   
	    	   shedudetail.setC09601(list.get(51));
	    	   shedudetail.setC09801(list.get(52));
	    	   shedudetail.setC09602(list.get(53));
	    	   shedudetail.setC09802(list.get(54));
	    	   shedudetail.setC09603(list.get(55));
	    	   shedudetail.setC09803(list.get(56));
	    	   shedudetail.setC09604(list.get(57));
	    	   shedudetail.setC09804(list.get(58));
	    	   shedudetail.setC10601(list.get(59));
	    	   shedudetail.setC10801(list.get(60));
	    	   shedudetail.setC10602(list.get(61));
	    	   shedudetail.setC10802(list.get(62));
	    	   
	    	   //添加排产详情（未做校验）
	    	   int insert = shedudetailServise.insert(shedudetail);
	    	   if (insert == 0) {
	    		   flag = 0;
	    		   break;
	    	   }
	       }
	       response.getWriter().print(flag);
	    }
	
	/**
	 * 提交审核(app)
	 * @param id 排产单id
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/subShedu")
	public void subShedu(Long id, HttpServletResponse response) throws Exception {
		//根据id修改排产单状态为：审核中
		Shedu record = new Shedu();
		record.setId(id);
		record.setRemark3("审核中");
		int affact = sheduServise.updateByPrimaryKeySelective(record );
		
		if(affact > 0) {
			
			List<String> list = sheduServise.selectManager();
			
			for (String s : list) {
				int testSendPush = PushExample.testSendPush("您有一个新的排产单需要审批", "您有一个新的排产单需要审批", s, "1");
				System.err.println(testSendPush);
			}
		}
		ResponseUtil.write(response, affact);
	}
	
	/**************************************************************排产单与安卓接口***********************************************************/
	
	/**
	 * 查询待审批的排产列表
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/selectSheduList")
	public void selectSheduList(HttpServletResponse response) throws Exception {
		
		SheduExample example = new SheduExample();
		com.sdry.model.jyy.SheduExample.Criteria createCriteria = example.createCriteria();
		createCriteria.andRemark3EqualTo("审核中");
		List<Shedu> list = sheduServise.selectByExample(example );
    	
		JSONObject jsonObject=new JSONObject();
		if(list.size() > 0) {
	        jsonObject.put("state", 1);
	        jsonObject.put("message", "成功");
	        jsonObject.put("count", list.size());
	        jsonObject.put("data", list);
		}else {
	        jsonObject.put("state", 0);
	        jsonObject.put("message", "无数据");
	        jsonObject.put("count", list.size());
	        jsonObject.put("data", list);
		}
		
       
        ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 根据排产单id 查询 排产单详情
	 * @param id 排产单id
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/selectSheduDetailList")
	public void selectSheduDetailList(String id,HttpServletResponse response) throws Exception {
		
		ShedudetailExample example = new ShedudetailExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andRemark2EqualTo(id);
		List<Shedudetail> list = shedudetailServise.selectByExample(example);
    	
		JSONObject jsonObject=new JSONObject();
		if(list.size() > 0) {
	        jsonObject.put("state", 1);
	        jsonObject.put("message", "成功");
	        jsonObject.put("count", list.size());
	        jsonObject.put("data", list);
		}else {
	        jsonObject.put("state", 0);
	        jsonObject.put("message", "无数据");
	        jsonObject.put("count", list.size());
	        jsonObject.put("data", list);
		}
       
        ResponseUtil.write(response, jsonObject);
	}
	
	
	/**
	 * 根据排产单id修改（审批后修改审批相关字段）
	 * @param id 排产单id
	 * @param remark 审批人
	 * @param remark3 审批状态
	 * @param remark4 审批意见
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/edit2")
	public void edit2(String id, String remark,String remark3,String remark4,HttpServletResponse response) throws Exception {
		
		Shedu shedu = new Shedu();
		
		shedu.setId(Long.valueOf(id));
		shedu.setRemark(remark);
		shedu.setRemark3(remark3);
		shedu.setRemark4(remark4);
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String format2 = format.format(date);
		
		//审批时间
		shedu.setRemark2(format2);
		int affact = sheduServise.updateByPrimaryKeySelective(shedu);
		
		List<String> list=new ArrayList<>();
	
		
		JSONObject jsonObject=new JSONObject();
		if(affact > 0) {
	        jsonObject.put("state", 1);
	        list.add("成功");
	        jsonObject.put("data", list);
		}else {
	        jsonObject.put("state", 0);
	        jsonObject.put("message", "失败");
		}
		
		ResponseUtil.write(response, jsonObject);
	}


		/**
	 * 修改排产详情里边的数字
	 * @param shedudetail 排产详情
	 * @param response 响应
	 * @throws Exception 
	 */
	@RequestMapping("/editNum")
	public void editNum(Shedudetail shedudetail,HttpServletResponse response) throws Exception {
		int sub = 0;
		int affact = shedudetailServise.updateByPrimaryKeySelective(shedudetail);
		Shedudetail selectByPrimaryKey = shedudetailServise.selectById(shedudetail.getId());
		String substring = shedudetail.getRemark3().substring(1,2);
		if("1".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB1())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB1());
			}
			if(!"".equals(selectByPrimaryKey.getC1())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC1());
			}
			if(!"".equals(selectByPrimaryKey.getD1())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD1());
			}
			if(!"".equals(selectByPrimaryKey.getE1())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE1());
			}
			selectByPrimaryKey.setA1(sub+"");
		}else if("2".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB2())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB2());
			}
			if( !"".equals(selectByPrimaryKey.getC2())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC2());
			}
			if( !"".equals(selectByPrimaryKey.getD2())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD2());
			}
			if( !"".equals(selectByPrimaryKey.getE2())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE2());
			}
			selectByPrimaryKey.setA2(sub+"");
		}else if("3".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB3())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB3());
			}
			if(!"".equals(selectByPrimaryKey.getC3())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC3());
			}
			if(!"".equals(selectByPrimaryKey.getD3())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD3());
			}
			if(!"".equals(selectByPrimaryKey.getE3())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE3());
			}
			selectByPrimaryKey.setA3(sub+"");
		}else if("4".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB4())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB4());
			}
			if(!"".equals(selectByPrimaryKey.getC4())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC4());
			}
			if(!"".equals(selectByPrimaryKey.getD4())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD4());
			}
			if(!"".equals(selectByPrimaryKey.getE4())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE4());
			}
			selectByPrimaryKey.setA4(sub+"");
		}else if("5".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB5())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB5());
			}
			if(!"".equals(selectByPrimaryKey.getC5())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC5());
			}
			if(!"".equals(selectByPrimaryKey.getD5())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD5());
			}
			if(!"".equals(selectByPrimaryKey.getE5())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE5());
			}
			selectByPrimaryKey.setA5(sub+"");
		}else if("6".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB6())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB6());
			}
			if(!"".equals(selectByPrimaryKey.getC6())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC6());
			}
			if(!"".equals(selectByPrimaryKey.getD6())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD6());
			}
			if(!"".equals(selectByPrimaryKey.getE6())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE6());
			}
			selectByPrimaryKey.setA6(sub+"");
		}else if("7".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB7())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB7());
			}
			if(!"".equals(selectByPrimaryKey.getC7())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC7());
			}
			if(!"".equals(selectByPrimaryKey.getD7())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD7());
			}
			if(!"".equals(selectByPrimaryKey.getE7())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE7());
			}
			selectByPrimaryKey.setA7(sub+"");
		}else if("8".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB8())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB8());
			}
			if(!"".equals(selectByPrimaryKey.getC8())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC8());
			}
			if(!"".equals(selectByPrimaryKey.getD8())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD8());
			}
			if(!"".equals(selectByPrimaryKey.getE8())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE8());
			}
			selectByPrimaryKey.setA8(sub+"");
		}else if("9".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB9())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB9());
			}
			if(!"".equals(selectByPrimaryKey.getC9())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC9());
			}
			if(!"".equals(selectByPrimaryKey.getD9())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD9());
			}
			if(!"".equals(selectByPrimaryKey.getE9())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE9());
			}
			selectByPrimaryKey.setA9(sub+"");
		}else if("10".equals(substring)) {
			if(!"".equals(selectByPrimaryKey.getB10())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getB10());
			}
			if(!"".equals(selectByPrimaryKey.getC10())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getC10());
			}
			if(!"".equals(selectByPrimaryKey.getD10())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getD10());
			}
			if(!"".equals(selectByPrimaryKey.getE10())) {
				sub= sub+Integer.parseInt(selectByPrimaryKey.getE10());
			}
			selectByPrimaryKey.setA10(sub+"");
		}
		
		int affact2 = shedudetailServise.updateByPrimaryKeySelective(selectByPrimaryKey);
		
		ResponseUtil.write(response, affact2);
		
	}
	
}
